import router from './router'
import { getToken } from './composables/auth'
import { showFailToast } from 'vant';
//全局前置守卫
router.beforeEach(async (to, from, next) => {
  const token = getToken()
  
  //页面标题
  let title = (to.meta.title ? to.meta.title : "") + "-后台管理"
  document.title = title

  //无权限登录页跳转
  if (!token && to.path != '/login') {
    showFailToast('请先登录')
     next({ path: '/login' })
  }
  //防止重复登录
  else if (token && to.path == '/login') {
    showFailToast('请勿重复登录')
     next({ path: from.path ? from.path : "/" })
  }
  else next()

})

//全局后置守卫
router.afterEach((to, from) => {
  //关闭loading
})